package com.yitong.equipment.ui.home

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.LogUtils
import com.yitong.equipment.R
import com.yitong.equipment.base.BaseFragment
import com.yitong.equipment.databinding.FragmentClassifyBinding
import com.yitong.equipment.ext.init
import com.yitong.equipment.ui.adapter.ClassifyAdapter
import com.yitong.equipment.ui.viewmodel.ClassifyViewModel

class ClassifyFragment : BaseFragment<ClassifyViewModel, FragmentClassifyBinding>() {

    private val classifyAdapter: ClassifyAdapter by lazy { ClassifyAdapter(arrayListOf()) }

    override fun setContent(): Int {
        return R.layout.fragment_classify
    }
    override fun initView() {
        bindingView.recycleView.init(LinearLayoutManager(activity), classifyAdapter, false)
        classifyAdapter.apply {
            setOnItemClickListener { adapter, view, position ->
                startActivity(Intent(activity, CourseDetailActivity::class.java))
            }
        }

        bindingView.refreshLayout.run {
            setOnRefreshListener {
                Handler(Looper.getMainLooper()).postDelayed(Runnable {
                    var mutableListOf = mutableListOf<String>()
                    for (index in 0..7) {
                        mutableListOf.add("")
                    }
                    classifyAdapter.setList(mutableListOf)
                    this.finishRefresh()
                },500)
            }
        }


    }

     override fun firstLoad() {
         bindingView.refreshLayout.autoRefresh()
         var name = arguments?.get("name") as String
         LogUtils.dTag("name",name)
     }



    companion object {
        fun getInstance(name: String): ClassifyFragment {
            val fragment = ClassifyFragment()
            val bundle = Bundle()
            bundle.putString("name", name)
            fragment.arguments = bundle
            return fragment
        }
    }

}